//
//  CommtiTableViewController.m
//  消费100
//
//  Created by eliot on 16/3/31.
//  Copyright © 2016年 aleven. All rights reserved.
//

#import "CommtiTableViewController.h"
#import "SubmitDetailTableViewCell.h"
#import "JoinSucceedViewController.h"
@interface CommtiTableViewController ()

@end

@implementation CommtiTableViewController


+(CommtiTableViewController*)CreatTransactionDetailsTableViewController{
    
    UIStoryboard *story=[UIStoryboard storyboardWithName:@"Main" bundle:nil];
    
    CommtiTableViewController *CommtiTableViewController=[story instantiateViewControllerWithIdentifier:@"CommtiTableViewController"];
    
    return CommtiTableViewController;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.tableView.tableFooterView = [[UIView alloc] init];
    [self.tableView registerNib:[UINib nibWithNibName:@"SubmitDetailTableViewCell" bundle:nil] forCellReuseIdentifier:@"SubmitDetailTableViewCell"];
    self.tableView.backgroundColor = [UIColor colorWithRed:237/255.0 green:237/255.0 blue:237/255.0 alpha:1];
    self.title =  @"提交";
    /** 设置导航啦样式*/
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:19],NSForegroundColorAttributeName:[UIColor whiteColor]}];
    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor]}];
    self.navigationController.navigationBar.translucent = NO;

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

//创建模态导航控制器
-(void)creatNav:(UIViewController *)view{
    
    UINavigationController *nav=[[UINavigationController alloc] initWithRootViewController:view];
    nav.navigationBar.barTintColor = [UIColor colorWithRed:254/255.0 green:154/255.0 blue:37/255.0 alpha:1];
    view.navigationItem.leftBarButtonItem=[[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"icon_back"] style:UIBarButtonItemStylePlain target:self action:@selector(dismiss)];
    [self presentViewController:nav animated:YES completion:nil];
}

- (void)dismiss {
    [self dismissViewControllerAnimated:YES completion:nil];
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    return 3;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (section == 0) {
        return 5;
    }else if (section == 1){
        return 4;
    }else {
        return 1;
    }
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0) {
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
        if ( !cell) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
        }
        switch (indexPath.row) {
            case 0:
            {
                cell.textLabel.text = @"收货信息";
                cell.textLabel.textColor = [UIColor colorWithRed:82/255.0 green:82/255.0 blue:82/255.0 alpha:1];
            }
                break;
            case 1:
            {
                cell.textLabel.text = @"收件人";
                cell.textLabel.textColor = [UIColor colorWithRed:136/255.0 green:136/255.0 blue:136/255.0 alpha:1];
                cell.detailTextLabel.text = @"杨阿斯";
                cell.detailTextLabel.textColor = [UIColor blackColor];
            }
                break;
            case 2:
            {
                cell.textLabel.text = @"联系电话";
                cell.textLabel.textColor = [UIColor colorWithRed:136/255.0 green:136/255.0 blue:136/255.0 alpha:1];
                cell.detailTextLabel.text = @"请输入联系电话";
            }
                break;
            case 3:
            {
                cell.textLabel.text = @"城市地址";
                cell.textLabel.textColor = [UIColor colorWithRed:136/255.0 green:136/255.0 blue:136/255.0 alpha:1];
                cell.detailTextLabel.text = @"选择市区";
                UIImageView *iv = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_arrows"]];
                iv.frame = CGRectMake(0, 0, 18, 15);
                iv.contentMode = UIViewContentModeScaleAspectFit;
                cell.accessoryView = iv;
            }
                break;
            default:
            {
                cell.textLabel.text = @"详细地址";
                cell.textLabel.textColor = [UIColor colorWithRed:136/255.0 green:136/255.0 blue:136/255.0 alpha:1];
                cell.detailTextLabel.text = @"请输入详细地址";
            }
                break;
                
        }
        return  cell;
    }else if (indexPath.section == 1){
        if (indexPath.row == 0) {
            UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
            if ( !cell) {
                cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
                cell.textLabel.text = @"兑换信息";
                cell.textLabel.textColor = [UIColor colorWithRed:82/255.0 green:82/255.0 blue:82/255.0 alpha:1];
            }
            return  cell;
        }else if(indexPath.row == 1){
            SubmitDetailTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SubmitDetailTableViewCell" forIndexPath:indexPath];
            cell.iconIVW.constant = 90 / 320.0 * Width;
            cell.iconIVH.constant = 100 / 320.0  *Width;
            cell.priceLb.hidden = NO;
            return  cell;
        }else if(indexPath.row == 2){
            UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
            if ( !cell) {
                cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
                cell.textLabel.text = @"参与次数";
                cell.textLabel.textColor = [UIColor colorWithRed:82/255.0 green:82/255.0 blue:82/255.0 alpha:1];
                cell.detailTextLabel.text = @"2";
            }
            return  cell;
        }else {
            UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
            if ( !cell) {
                cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
                cell.textLabel.text = @"共需金币";
                 cell.textLabel.textColor = [UIColor colorWithRed:82/255.0 green:82/255.0 blue:82/255.0 alpha:1];
                cell.detailTextLabel.text = @"20";
            }
            return  cell;
        
        }
        
    }else {
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"lastCell"];
        if (!cell) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"lastCell"];
        }
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        [cell addSubview:btn];
        btn.backgroundColor = [UIColor colorWithRed:255/255.0 green:88/255.0 blue:88/255.0 alpha:1];
        [btn setTitle:@"提交" forState:UIControlStateNormal];
        [btn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(20);
            make.right.mas_equalTo(-20);
            make.top.mas_equalTo(5);
            make.height.mas_equalTo(35);
        }];
        [btn addTarget:self action:@selector(placeOrder) forControlEvents:UIControlEventTouchUpInside];
        btn.layer.cornerRadius = 8;
        btn.layer.masksToBounds = YES;
        cell.backgroundColor = [UIColor colorWithRed:230/255.0 green:230/255.0 blue:230/255.0 alpha:1];
        return cell;
    }
}



- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0) {
        return 44;
    }else if (indexPath.section == 1) {
        if (indexPath.row == 1) {
            return 90 / 320.0 * Width + 15;
        }else {
            return 44;
        }
    }else {
        return 65 / 320.0 * Width;
    }
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    if (section == 2) {
        return 20 / 667.0 *Height;
    }else {
        return 10;
    }
}



/** 提交*/
- (void)placeOrder {
    
    JoinSucceedViewController *vc = [JoinSucceedViewController CreatJoinSucceedViewController];
    [self creatNav:vc];
    
}
//
/** 提交订单*/
//- (void)placeOrder {
////    PayDetailTableViewController *vc = [PayDetailTableViewController CreatTransactionDetailsTableViewController];
////    
////    [self creatNav:vc];
//    
//}
/*
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:<#@"reuseIdentifier"#> forIndexPath:indexPath];
    
    // Configure the cell...
    
    return cell;
}
*/

/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
